import Vue from 'vue'
import Router from 'vue-router'
import Store from '@/store/index'
import I18n from '@/assets/plugin/lang/index'
// 公共区域
import Header from '@/views/common/header'
import Footer from '@/views/common/footer'
// // 首页
// import ArticleContent from '@/components/content/ArticleContent'
// import BookNoteContent from '@/components/content/BookNoteContent'
// import BookContent from '@/components/content/BookContent'
// import ArticleListContent from '@/components/content/ArticleListContent'
// import BookListContent from '@/components/content/BookListContent'
// import TimeLineContent from '@/components/content/TimeLineContent'
// import SearchResultContent from '@/components/content/SearchResultContent'

Vue.use(Router)

const router = new Router({
	model: 'history',
	// 每次访问滚动条都置0
	scrollBehavior: () => ({
		y: 0
	}),
	routes: [{
		path: '/',
		meta: {
			title: I18n.tc('route.title.main')
		},
		component: resolve => require(['@/views/main'], resolve),
		children: [{
			path: '/',
			name: 'home',
			meta: {
				title: I18n.tc('route.title.home')
			},
			components: {
				header: Header,
				content: resolve => require(['@/views/common/content/home-content'], resolve),
				footer: Footer
			}
		}]
	}]
})

router.beforeEach((to, from, next) => {
	if (to.meta && to.meta.title) {
		document.title = to.meta.title
		Store.commit('common/SET_NAVTITLE', to.meta.title)
	}
	next()
})

router.afterEach((to, from, next) => {
	window.scrollTo(0, 0)
})

export default router
